package com.lry.basic.redis;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import redis.clients.jedis.Jedis;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class SetApply {

    private Jedis jedis;

    @BeforeAll
    public void before(){
        jedis = RedisPool.getJedis();
    }

    @AfterAll
    public void after(){
        RedisPool.release(jedis);
    }

    @Test
    public void tag(){
        String user1Tag = "user:1:tag";
        String user2Tag = "user:2:tag";
        jedis.sadd(user1Tag,"lol","music","play","video");
        jedis.sadd(user2Tag,"lol","music","play","eat");
        //公共爱好
        System.out.println(jedis.sinter(user1Tag, user2Tag));
        //差集
        System.out.println(jedis.sdiff(user1Tag, user2Tag));
        //并集
        System.out.println(jedis.sunion(user1Tag, user2Tag));

        for(int i=0;i<10;i++){
            //随机取
            System.out.println(jedis.srandmember(user1Tag));
        }
//        jedis.spop(user1Tag);//随机弹出
    }





}
